// @File:           @File test1.c
// @ProjectName:    gee_logger_c
// @Description:    ${description}
// @Author:         wujehy
// @Email:          wujehy@qq.com
// @Time:           2021-03-28 23:39

#include <iostream>
#include <sstream>
#include "logger_c.h"
#include "thread"
#include <unistd.h>
#include <sys/time.h>

void test_fun() {
    GTestDebug(1, 1, "this is test func ");

}

int64_t get_cueent_time() {
    struct timeval tv;
    gettimeofday(&tv, NULL);
    unsigned long long current_time = tv.tv_sec * 1000 + tv.tv_usec / 1000;
    return current_time;

}

int main() {

    // 初始化
    init_logger_service("127.0.0.1", 8080);
    int64_t start_time = get_cueent_time();
    printf("start Time : %ld \n", start_time);
    // 10000 time
    for (int i = 0; i < 4; i++) {
        int pid = fork();
        if (pid < 0) {
            perror("fork failed");
            exit(1);
        }

        for (int i = 0; i < 1000; ++i) {
            std::stringstream ss;
            ss << "log info test tid : " << pid << " time :" << i;
            GTestDebug(1, 1, ss.str().c_str());
        }
        if (pid == 0) {
            // 子进程直接结束
            int64_t end_time = get_cueent_time();
            auto thread_id = getpid();
            printf("chind end time = %ld , start - end = %ld , %d \n", end_time, end_time - start_time, thread_id);
            printf("end chind \n");
            return 0;
        } else {

        }
    }

    int64_t end_time = get_cueent_time();
    auto thread_id = getpid();
    printf(" end time = %ld , start - end = %ld , %d \n", end_time, end_time - start_time, thread_id);
    // 反初始化
    deinit_logger_service();
    return 0;
}